package view.impl.ingame.animation;


import org.newdawn.slick.Animation;




import sharedGameLogic.enums.BattleDistance;
import view.impl.ingame.EffectDispatch;
import view.impl.ingame.Fighter;

/**
 * @author Julian
 *
 */
public class AttackAction extends ActionAnimation {

	private int hitPosX = 0;
	private int hitPosY = 0;
	private int hitFrame = 0;
	
	private Effect effect = null;
	private BattleDistance effectDist;
	
	private boolean effectAdded = false;
	
	public AttackAction(Animation anim, int offsetX, int offsetY, String effectName, int hitPosX, int hitPosY, int hitFrame, BattleDistance effectDist, boolean mirrored, Fighter owner) throws EffectLoadException {
		super(anim, offsetX, offsetY, mirrored);
		this.hitPosX = hitPosX;
		this.hitPosY = hitPosY;
		this.hitFrame = hitFrame;
		this.effectDist = effectDist;
		
		effect = new Effect(effectName, owner);
	}
	
	/*
	void drawEffects(float posX, float posY, float width, float height, int delta) {
		if(anim.getFrame() >= hitFrame) {
			int x = !mirrored ? (int)posX + hitPosX : (int)posX + anim.getWidth() - hitPosX;
			int y = (int)posY + anim.getHeight() - hitPosY;
			effect.draw(x, y, delta);
		}
	}
	*/
	
	public void addEffects(float posX, float posY, EffectDispatch ed, boolean successfulAttack) {
		if(anim.getFrame() >= hitFrame && !effectAdded) {
			int x = !mirrored ? (int)posX + hitPosX : (int)posX + anim.getWidth() - hitPosX;
			int y = (int)posY + anim.getHeight() - hitPosY;
			effect.setPos(x, y);
			effect.setSuccess(successfulAttack);
			
			effect.restart();
			ed.addEffect(effect);
			
			effectAdded = true;
		}
	}

	@Override
	public void restart() {
		super.restart();
		effect.restart();
		effectAdded = false;
	}
			
	/* (non-Javadoc)
	 * @see client.view.ActionAnimation#getActionType()
	 */
	@Override
	public EActionType getActionType() {
		return EActionType.ATTACK;
	}
	
	public BattleDistance getEffectDist() {
		return effectDist;
	}
}
